export default{
    state: {
        //登录的状态
        loginStatus:false,
        //token
        token:null,
        //用户信息
        userInfo:{}
    },
    mutations: {
        //初始化登录
        inuser(state){
            let userinfo=window.localStorage.getItem('userInfo');
            if (userinfo) {
                userinfo=JSON.parse(userinfo);
                state.loginStatus=true
                state.token=userinfo.token;
                state.userInfo=userinfo
            }
        },
        //登录
        login(state,userinfo){
            state.userInfo=userinfo,
            state.loginStatus=true,
            state.token=userinfo.token,
            //持久化登录
            window.localStorage.setItem("userInfo",JSON.stringify(userinfo))
        },
        //退出登录
        loginout(state){
            state.userInfo={ },
            state.loginStatus=false,
            state.token=null,
            //持久化登录
            window.localStorage.removeItem("userInfo")
        }
    }
}